package com.ahoi.common.utils;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * author: ahoi
 * date: 2018/8/30 16:58
 * description: 线程工具类
 */
public class ThreadUtils {

    // 存活的线程数
    public static AtomicInteger threadAliveCount;


    public static void iniThreadAliveCount(Integer initValue) {
        threadAliveCount = new AtomicInteger(initValue);
    }

    public static void incThreadAliveCount() {
        threadAliveCount.incrementAndGet();
    }

    public static void decThreadAliveCount() {
        threadAliveCount.decrementAndGet();
    }

    public static synchronized int getThreadAliveCount() {
        return threadAliveCount.intValue();
    }

    public static void startNewThread(String threadName, Runnable runnable) {
        Thread thread = new Thread(runnable);
        thread.setName(threadName);
        thread.start();
    }

    public static String getThreadName() {
        return Thread.currentThread().getName();
    }

}
